package controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jdk.nashorn.internal.scripts.JO;

import com.google.gson.JsonObject;

import model.Company;
import dao.companyDAO;

/**
 * Servlet implementation class CompanyDetailController
 */
@WebServlet(urlPatterns="/CompanyDetailController")
public class CompanyDetailController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CompanyDetailController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		companyDAO dao = new companyDAO();
		String commanyId = request.getParameter("companyId");
		Company company = dao.getCompanyById(Integer.parseInt(commanyId));
		JsonObject json = new JsonObject();
		json.addProperty("companyId", company.getCompanyId());
		json.addProperty("companyName", company.getCompanyName());
		json.addProperty("address", company.getAddress());
		json.addProperty("phoneNumber",company.getPhoneNumber());
		json.addProperty("contactPerson",company.getContactPerson());
		json.addProperty("contactPerson",company.getContactPerson());
		json.addProperty("typeOfCompany", company.getCompanyType().getCompanyTypeId());
		json.addProperty("noWorkers",company.getNoWorkers());
		json.addProperty("noLines",company.getNoLines());
		json.addProperty("noMachines",company.getNoMachinesLine());
		json.addProperty("noBranches",company.getNoBranches());
		json.addProperty("capacity",company.getCapacityOfDayMonth());
		json.addProperty("timeOfMaterials",company.getTimeTextile());
		json.addProperty("timeOfOrigin",company.getTimeTextileOrigin());
		/**
		 * con mot so thuoc tinh
		 */

		System.out.println(company.getCompanyName());
		response.getWriter().print(json);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
